package com.cloudwise.controller;

import cn.hutool.db.Entity;
import com.cloudwise.service.PersonService;
import com.cloudwise.service.impl.PersonServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2023/2/15 16:12
 * @description：人员业务控制器
 * @modified By：
 * @version:1.0
 */
@WebServlet(name = "PersonController" ,value = "/person")
public class PersonController extends HttpServlet {
    PersonService personService = new PersonServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String requestURI = req.getRequestURI();
        String contextPath = req.getContextPath();
        System.out.println("请求的路径"+requestURI);
        System.out.println("请求的项目名称"+contextPath);
        //去service层获取数据
        List<Entity> entityList = personService.queryAll();
      //将数据响应给前端jsp页面，将数据存储到jsp内置对象中
        req.setAttribute("personList",entityList);
        //设置目标页面 showPerson.jsp
        req.getRequestDispatcher("showPerson.jsp").forward(req,resp);

    }
}
